#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

class Main {
	int n, m;
	vector<int> father;
	vector<int> rel;

	int find(int x)
	{
		if (x != father[x]) {
			int t = father[x];
			father[x] = find(t);
			rel[x] ^= rel[t];
		}
		return father[x];
	}

	void unite(int x, int y, int val)
	{
		int fx = find(x);
		int fy = find(y);

		if (fx != fy) {
			father[fx] = fy;
			rel[fx] = rel[x] ^ rel[y] ^ val;
		}
	}

    public:
	Main(int n, int m) : n(n), m(m), father(n + 1, 0), rel(n + 1, 0)
	{
		iota(father.begin(), father.end(), 0);
	}

	void run()
	{
		char rlt;
		int x, y;
		vector<vector<int>> relation;
		for (int i = 0; i < m; i++) {
			cin >> rlt >> x >> y;
			relation.push_back({ x, y, rlt == 'F' ? 0 : 1 });
			unite(x, y, rlt == 'F' ? 0 : 1);
		}

                set<pair<int, int>> mset;
		for (int i = 1, p; i <= n; i++) {
			p = find(i);
			mset.insert({ p, rel[i] });
		}

		for (int i = 0; i < relation.size(); i++) {
			x = relation[i][0];
			y = relation[i][1];
			int r = relation[i][2];
			if (find(x) != find(y)) {
				cout << "ERR" << endl;
				break;
			}
			if ((rel[x] ^ rel[y]) != r) {
				cout << "ERROR" << endl;
				break;
			}
		}

		cout << mset.size() << endl;
	}
};

int main()
{
	int n, m;
	cin >> n >> m;
	Main app(n, m);
	app.run();
	return 0;
}